package com.lanou.projecta.news;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.projecta.R;

import java.util.ArrayList;

/**
 * Created by dllo on 16/1/11.
 */
public class NewsPagerAdapter extends FragmentPagerAdapter {
    private ArrayList<Fragment> data;
    private Context context;
    String titleheadline = "头条";
    String titlemilitary = "军事";
    String titlecomic = "漫画";
    String titleentertainment = "娱乐";
    String titlefashion = "时尚";
    String titlegame = "游戏";
    String titlehistory = "历史";
    String titlehot = "热点";
    String titlescience = "科技";
    String titlesports = "体育";
    String titlesJokes = "段子";


    String[] titles = {titleheadline, titlemilitary,titlecomic,titleentertainment,titlefashion
        ,titlegame,titlehistory,titlehot,titlescience,titlesports,titlesJokes};

    public NewsPagerAdapter(FragmentManager fm, ArrayList<Fragment> data, Context context) {
        super(fm);
        this.data = data;
        this.context = context;
    }

    @Override
    public Fragment getItem(int position) {
        return data.get(position);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    public CharSequence getPageTitle(int position) {
        return titles[position];
    }

    public View getTabView(int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.fragment_news_tab, null);
        TextView textView = (TextView) view.findViewById(R.id.tv_news);
        textView.setText(titles[position]);
        return view;

    }
}
